package lib

import (
	"gitee.com/zawei/yggdrasil/pkg"
	"gitee.com/zawei/yggdrasil/pkg/log"
	"gitee.com/zawei/yggdrasil/pkg/metrics"
)

const (
	MetricsLibHandleStats = "lib_handle_stats"
	MetricsLibHandleTotal = "lib_handle_total"
	MetricsLibHandleSec   = "lib_handle_seconds"
)

func registryMetric() {
	err := metrics.CreateSummary(metrics.SummaryOpts{
		Namespace: pkg.FrameworkName(),
		Subsystem: pkg.AppName(),
		Name:      MetricsLibHandleStats,
		Labels:    []string{"name", "status"},
	})
	if err != nil {
		log.Fatalw("fault to registry lib metric", "error", err)
	}
	err = metrics.CreateHistogram(metrics.HistogramOpts{
		Namespace: pkg.FrameworkName(),
		Subsystem: pkg.AppName(),
		Name:      MetricsLibHandleSec,
		Labels:    []string{"type", "method", "address"},
	})
	if err != nil {
		log.Fatalw("fault to registry lib metric", "error", err)
	}
	err = metrics.CreateCounter(metrics.CounterOpts{
		Namespace: pkg.FrameworkName(),
		Subsystem: pkg.AppName(),
		Name:      MetricsLibHandleTotal,
		Labels:    []string{"type", "method", "address", "code"},
	})
	if err != nil {
		log.Fatalw("fault to registry lib metric", "error", err)
	}
}

func Init() {
	registryMetric()
}
